<template class="firstpage">
  <div>
    <div class="boxMargin" @click="ladingRegion">
      <el-card class="box-card">
        <el-row class="margin" :gutter="20">
          <el-col :span="8">
            <el-row>
              <el-col :span="8" class="inputName">taskId：</el-col>
              <el-col :span="14">
                <el-input v-model="searchData.taskId" placeholder="请输入taskId" />
              </el-col>
            </el-row>
          </el-col>
          <el-col :span="8">
            <el-row>
              <el-col :span="8" class="inputName">platformId：</el-col>
              <el-col :span="14">
                <el-input v-model="searchData.platformId" placeholder="请输入第三方平台id" />
              </el-col>
            </el-row>
          </el-col>
        </el-row>
        <el-row class="margin" :gutter="20">
          <el-col :span="8">
            <el-row>
              <el-col :span="8" class="inputName">处理结果：</el-col>
              <el-col :span="14">
                <el-select v-model="searchData.syncResult" placeholder="请选择">
                  <el-option
                    v-for="task in customData.syncResult"
                    :key="task.value"
                    :label="task.label"
                    :value="task.value"
                  />
                </el-select>
              </el-col>
            </el-row>
          </el-col>
          <el-col :span="8">
            <el-row>
              <el-col :span="8" class="inputName">处理类型：</el-col>
              <el-col :span="14">
                <el-select v-model="searchData.syncType" placeholder="请选择">
                  <el-option
                    v-for="task in customData.syncType"
                    :key="task.value"
                    :label="task.label"
                    :value="task.value"
                  />
                </el-select>
              </el-col>
            </el-row>
          </el-col>
        </el-row>
        <el-row class="margin">
          <el-col :span="24" class="right">
            <el-button type="success" @click="onSearch">查询</el-button>
            <el-button @click="onReset">清空</el-button>
          </el-col>
        </el-row>
      </el-card>
    </div>
    <div class="boxMargin">
      <el-card class="box-card">
        <div slot="header">
          <div class="contion-header" style="width:10%;">
            <span>子任务管理列表</span>
          </div>
        </div>
        <div>
          <el-table
            :data="tableData"
            tooltip-effect="dark"
            style="width: 100%"
            @selection-change="handleSelectionChange"
          >
            <el-table-column prop="taskId" label="任务id" />
            <el-table-column prop="subTaskId" label="子任务id" />
            <el-table-column prop="platformId" label="第三方平台id" />
            <!--                        <el-table-column prop="contentId" label="MongoID" style="color: #20a0ff" @click="commodTaskContent(contentId)"></el-table-column>-->
            <el-table-column prop="contentId" label="MongoID">
              <template slot-scope="scope">
                <span style="color: #1890ff;cursor: pointer;" @click="commodTaskContent(scope.row)">{{ scope.row.contentId }}</span>
              </template>
            </el-table-column>
            <el-table-column prop="syncResult" label="处理结果" />
            <el-table-column prop="syncType" label="处理类型" />
            <el-table-column prop="dataMd5" label="数据对象md5" />
            <el-table-column prop="createTime" label="创建时间" />
            <el-table-column prop="lastModifyTime" label="更新时间" />
          </el-table>
        </div>
      </el-card>
    </div>
    <div class="marginTop20 center">
      <template>
        <PAGER ref="wptxPager" @search="onChangePage" />
      </template>
    </div>
    <el-dialog title="Mongo信息" :visible.sync="customData.commodities" width="40%" center>
      <el-form ref="form" :model="form" :rules="rules" label-width="140px" class="demo-ruleForm">
        <el-form-item label="详细信息">{{ form.contentTask }}</el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>
<script>
import _validate from '../../../../framework/commonJs/wptx_validate'
import _tools from '../../../../framework/commonJs/wptx_tools'
import _api from '@/framework/API/subTask'
import { PAGER } from '@/framework/commonTemplate/'
const _FUNCTION_NAME = ''
export default {
  components: { PAGER },
  filters: {},
  data() {
    return {
      tableData: [],
      searchData: {
        syncResult: '', // 任务类型，0：商品，1：商品图片，2：商品文描，3：商品分类属性，4：商品视频，5：hostUpc
        syncType: '', // 任务状态 0：未执行；1：成功；2：失败；3：处理中
        taskId: '', // master_sync_task表主键ID
        platformId: '' // 第三方平台id
      },
      searchDataBuffer: {
        syncResult: '',
        syncType: '',
        taskId: '',
        platformId: ''
      },
      pageData: {
        pageNo: 1,
        pageSize: 10,
        total: 1,
        pageSizes: [10, 20, 50, 100]
      },
      dialogData: {},
      historyData: {},
      infoData: {},
      filterText: '',
      customData: {
        syncResult: [
          { label: '--请选择--', value: '' },
          { label: '成功', value: 0 },
          { label: '失败', value: 1 },
          { label: '未处理', value: 2 }
        ],
        syncType: [
          { label: '--请选择--', value: '' },
          { label: '新增', value: 0 },
          { label: '更新', value: 1 }
        ],
        commodValue: {
          contentId: ''
        },
        commodities: false,
        commoditiesDate: []
      },
      form: {},
      rules: {}
    }
  },
  computed: {},
  watch: {
    filterText(val) {
      this.$refs.tree.filter(val)
    }
  },
  created() {
  },
  mounted() {
    this._FUNCTION_NAME = this.$route.name
    this.onInit()
  },
  beforeDestroy() {
  },
  methods: {
    onInit(data) {
      const self = this
      const params = self.$route.query.taskId
    },
    onSearch() {
      const self = this
      const params = self.searchData
      self.searchDataBuffer = _tools.cloneObj(self.searchData)
      self.$refs.wptxPager.resetPageNo()
      _api.page(self, self.$refs.wptxPager.pageData, self.callBack_page, params)
    },
    onChangePage(data) {
      const self = this
      const params = self.searchDataBuffer
      _api.page(self, self.$refs.wptxPager.pageData, self.callBack_page, params)
    },
    onReset(data) {
      const self = this
      _tools.reset(self.searchData)
      _tools.reset(self.searchDataBuffer)
      self.onInit()
    },
    onAdd(data) {
    },
    onDelete(data) {
      const self = this
    },
    onInfo(data) {
      const self = this
    },
    onBathDelete() {
      const self = this
    },
    onBathUpdate() {
    },
    onDisable(data) {
      const self = this
    },
    onEnable(data) {
      const self = this
    },
    onUpload(data) {
    },
    onBathUpload() {
    },
    onExport(data) {
    },
    onDownload(data) {
    },
    onHistory(data) {
    },
    callBack_page(data) {
      const self = this
      if (_validate.checkEmpty(data)) {
        _validate.openTip(self, '返回数据为空', 'warning')
      } else {
        self.tableData = data.result
        self.$refs.wptxPager.updatePageData(data)
      }
    },
    callBack_pageMongoContent(data) {
      const self = this
      if (_validate.checkEmpty(data)) {
        _validate.openTip(self, '返回数据为空', 'warning')
      } else {
        self.customData.commoditiesDate = data.data
        self.$nextTick(function() {
          self.form = data.data
          self.$refs['form'].resetFields()
        })
      }
    },
    ladingRegion() {
      this.customData.treeModel = false
    },
    handleSelectionChange(val) {
      this.customData.multipleSelection = val
    },
    commodTaskContent(data) {
      const self = this
      self.customData.commodities = true
      self.customData.commodValue.contentId = data.contentId
      self.commodChange()
    },
    commodChange() {
      const self = this
      const params = {
        pageNo: self.pageData.pageNo,
        pageSize: self.pageData.pageSize
      }
      _api.pageMongoContent(self, params, self.callBack_pageMongoContent, self.customData.commodValue)
    }
  }
}
</script>

<style scoped>
    .contion-header {
        display: inline-block;
        box-sizing: border-box;
    }
    .tree-div {
        position: absolute;
        height: auto;

        z-index: 10;
        overflow-y: scroll;
        width: 58%;
        background: #EEE;
    }
    .tree {
        max-height: 200px;
        background: #EEE;
    }
    .el-card {
        overflow: visible;
    }
</style>
